#include <STC15F2K60S2.H>
#include "Delay.h"
#include "Nixie.h"
#include "ADC_128S102.h"



#define ADC_1	0x00

unsigned int ADValue;
unsigned int ADValue1;


unsigned int middleValueFilter()
{
    unsigned long sum = 0;
    unsigned char i;
    for(i = 0; i < 5;i++)
    {
        sum += ADValue;
    }
    return sum/5;
}

void ADC(unsigned int x)
{
 
	
	
	  Nixie1(4,x%10);
		Delay(4);
  	Nixie1(3,x/10%10);
		Delay(4);
		Nixie1(2,x/100%10);
		Delay(4); 
	  Nixie1(1,x/1000%10);
		Delay(4);


}		
	
		
void Timer0Init(void)
{
	TMOD &= 0xF0;		
	TMOD |= 0x01;		
	TL0 = 0x18;		
	TH0 = 0xFC;		
	TF0 = 0;		
	TR0 = 1;		
	ET0=1;
	EA=1;
	PT0=0;
}

void main(void)
{

	P0M0=0x00;
	P0M1=0x00;
	P1M0=0x00;
	P1M1=0x00;
	P4M0=0x00;
	P4M1=0x00;
  Timer0Init();	
	while(1)
	{	
		ADValue1=middleValueFilter();
		ADC(ADValue1*0.82);
	}
}

void Timer0_Routine() interrupt 1
{
	static unsigned int T0Count;
	TL0 = 0x18;
	TH0 = 0xFC;	
	T0Count++;
	if(T0Count>=1000)
	{
		ADValue=0;
		ADValue=ADC_ReadAD(ADC_1); 
		T0Count=0;
		
	}
}



